package YahooFinance.network;

public class ResponseParser {
	
    String response;
    String[] lines;

    public ResponseParser(String _response) {
        response = _response;
        lines = response.split("\n");
    }

    String valueForEqualsKey(String key) {
        String prefix = key + "=";
        for (String line : lines) {
        	String temp = line.replaceAll("[\n\r]", "");
            if (temp.startsWith(prefix)) {
                String[] e = temp.split("=");
                if (e.length > 1) {
                    return e[1];
                }
            }
        }
        return null;
    }
    String valueForSeperatedKey(String key) {
        String prefix = key + ";";
        for (String line : lines) {
        	String temp = line.replaceAll("[\n\r]", "");
            if (temp.startsWith(prefix)) {
                String[] e = temp.split(";");
                if (e.length > 1) {
                    return e[1];
                }
            }
        }
        return null;
    }
   
    public boolean isSuccess() {
        return "\"OK\"".equals(valueForEqualsKey("STATUS_CODE"));
  
    }
}
